package com.xcity.game.achievement.helper;

import com.xcity.db.entity.Player;
import com.xcity.game.achievement.Achievement;
import com.xcity.game.achievement.Achievement.State;
import com.xcity.game.achievement.AchievementHelper;
import com.xcity.game.achievement.AchievementTemplate;
import com.xcity.game.battle.pve.PVEStage;

/**
 * 成就类型：拓展通关<br/>
 * 1个参数：①关卡id
 * @author yang.li
 *
 */
public class PassPVEHelper implements AchievementHelper {

	@Override
	public boolean update(Achievement refer, int... vals) {
		return isFinished(refer);
	}

	@Override
	public boolean isFinished(Achievement refer) {
		if (refer.getState() == State.INITED) {
			Player player = refer.getVm().getOwner();
			PVEStage stage = player.getPveStages().getStage(obtainId(refer.getTemplate()));
			if (stage != null && stage.isPass()) {
				refer.setState(State.FINISHED);
				return true;
			}
		}
		return false;
	}
	
	static int obtainId(AchievementTemplate template) {
		return (int) template.getCondition(0);
	}
	
}
